package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import src.MyDynamicStack;

public class MyDynamicStackTest {

	@Test
	public void testMyDynamicStack() {
		MyDynamicStack ds = new MyDynamicStack(1);
		ds.push(5);
		assertTrue(ds.isStackFull());
	}

	@Test
	public void testPush() {
		MyDynamicStack ds = new MyDynamicStack(2);
		ds.push(4);
		ds.push(5);
		assertEquals(ds.peek(), 5);
		assertTrue(ds.isStackFull());

		ds.push(6);
		assertEquals(ds.peek(), 6);
		assertFalse(ds.isStackFull());

		ds.push(6);
		assertTrue(ds.isStackFull());

	}

	@Test
	public void testPop() {
		MyDynamicStack ds = new MyDynamicStack(1);

		try {
			ds.push(5);
			assertEquals(ds.pop(), 5);
			assertTrue(ds.isStackEmpty());
		} catch (Exception e) {
		}

		try {
			ds.pop();
		} catch (Exception e) {
			assertTrue(ds.isStackEmpty());
		}

	}

	@Test
	public void testPeek() {
		MyDynamicStack ds = new MyDynamicStack(10);

		try {
			ds.peek();
		} catch (Exception e) {
			assertTrue(ds.isStackEmpty());
		}
		ds.push(5);
		assertEquals(ds.peek(), 5);
	}

	@Test
	public void testIsStackEmpty() {
		MyDynamicStack ds = new MyDynamicStack(1);
		assertTrue(ds.isStackEmpty());
		ds.push(5);
		assertFalse(ds.isStackEmpty());
		try {
			ds.pop();
		} catch (Exception e) {
		}
		assertTrue(ds.isStackEmpty());
	}

	@Test
	public void testIsStackFull() {
		MyDynamicStack ds = new MyDynamicStack(1);
		assertFalse(ds.isStackFull());
		ds.push(5);
		assertTrue(ds.isStackFull());
		try {
			ds.pop();
		} catch (Exception e) {
		}
		assertFalse(ds.isStackFull());

	}

}
